#Obtaining the full sample of all authors (do only once)#


library(igraph)
source("getntwrks7auth.R")
source("analyzenetw.R")

data<-read.csv("networkgender7017.csv",header=TRUE)

# endyears and length to compute networks
ks <- 5
for (k in ks) {
 endyears <- (1970+k-1):2017

  for (endyear in endyears) {
    startyear <- endyear - k+1

    y <- subset(data,year>=startyear & year<=endyear)
    g <- getnetwork(startyear,endyear, data)
    y$auth7[is.na(y$auth7)]<--6 
    y$auth6[is.na(y$auth6)]<--5 
    y$auth5[is.na(y$auth5)]<--4 
    y$auth4[is.na(y$auth4)]<--3 
    y$auth3[is.na(y$auth3)]<--2 
    y$auth2[is.na(y$auth2)]<--1  

    V(g)$deg <- degree(g)
    #V(g)[deg>0]$netprod <- sapply(V(g)[deg>0],netprod,g,y)
    V(g)$auth<-V(g)
    #V(g)[deg>0]$netprod2<-sapply(V(g)[deg>0],netprod2,g,y)
    V(g)$deg2<- neighborhood.size(g, 2) - V(g)$deg - 1
    V(g)$tran<-transitivity(g, type="local",isolates="NaN")
#COMPUTING THE CENTRALITY VARIABLES
    gc<-get.giant.component(g)
    V(gc)$deg<-degree(gc)
    V(gc)$bet<-betweenness(gc)
    V(gc)$tr<-transitivity(gc, type="local",isolates="NaN")
    V(gc)$cl<-closeness(gc, normalized=TRUE)
    V(gc)$ev<-evcent(gc)$vector
   

    d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran)
    d2<-data.frame(V(gc)$auth,V(gc)$deg,V(gc)$bet,V(gc)$cl,V(gc)$ev, V(gc)$tr)

    write.csv(d,file=paste("network", endyear, "_", k, "y.csv", sep=""),na=".")
    write.csv(d2,file=paste("networkgc", endyear, "_", k, "y.csv", sep=""),na=".")
  }
}

#SUPLEMENTARY APPENDIX
#Other periods: 3 years
library(igraph)
source("getntwrks7auth.R")
#source("netprod_7authors.R")
#source("netprod2_7authors.R")
source("analyzenetw.R")

data<-read.csv("networkgender7017.csv",header=TRUE)

# endyears and length to compute networks
ks <- 3
for (k in ks) {
 endyears <- (1970+k-1):2017

  for (endyear in endyears) {
    startyear <- endyear - k+1

    y <- subset(data,year>=startyear & year<=endyear)
    g <- getnetwork(startyear,endyear, data)
    y$auth7[is.na(y$auth7)]<--6 
    y$auth6[is.na(y$auth6)]<--5 
    y$auth5[is.na(y$auth5)]<--4 
    y$auth4[is.na(y$auth4)]<--3 
    y$auth3[is.na(y$auth3)]<--2 
    y$auth2[is.na(y$auth2)]<--1  

    V(g)$deg <- degree(g)
    #V(g)[deg>0]$netprod <- sapply(V(g)[deg>0],netprod,g,y)
    V(g)$auth<-V(g)
    #V(g)[deg>0]$netprod2<-sapply(V(g)[deg>0],netprod2,g,y)
    V(g)$deg2<- neighborhood.size(g, 2) - V(g)$deg - 1
    V(g)$tran<-transitivity(g, type="local",isolates="NaN")
#COMPUTING THE CENTRALITY VARIABLES
    gc<-get.giant.component(g)
    V(gc)$deg<-degree(gc)
    V(gc)$bet<-betweenness(gc)
    V(gc)$tr<-transitivity(gc, type="local",isolates="NaN")
    V(gc)$cl<-closeness(gc, normalized=TRUE)
    V(gc)$ev<-evcent(gc)$vector
   

    #d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran, V(g)$netprod,V(g)$netprod2)
    d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran)
    d2<-data.frame(V(gc)$auth,V(gc)$deg,V(gc)$bet,V(gc)$cl,V(gc)$ev, V(gc)$tr)

    write.csv(d,file=paste("network", endyear, "_", k, "y.csv", sep=""),na=".")
    write.csv(d2,file=paste("networkgc", endyear, "_", k, "y.csv", sep=""),na=".")
  }
}

#Other periods: 10 years
library(igraph)
source("getntwrks7auth.R")
#source("netprod_7authors.R")
#source("netprod2_7authors.R")
source("analyzenetw.R")

data<-read.csv("networkgender7017.csv",header=TRUE)

# endyears and length to compute networks
ks <- 10
for (k in ks) {
 endyears <- (1970+k-1):2017

  for (endyear in endyears) {
    startyear <- endyear - k+1

    y <- subset(data,year>=startyear & year<=endyear)
    g <- getnetwork(startyear,endyear, data)
    y$auth7[is.na(y$auth7)]<--6 
    y$auth6[is.na(y$auth6)]<--5 
    y$auth5[is.na(y$auth5)]<--4 
    y$auth4[is.na(y$auth4)]<--3 
    y$auth3[is.na(y$auth3)]<--2 
    y$auth2[is.na(y$auth2)]<--1  

    V(g)$deg <- degree(g)
    #V(g)[deg>0]$netprod <- sapply(V(g)[deg>0],netprod,g,y)
    V(g)$auth<-V(g)
    #V(g)[deg>0]$netprod2<-sapply(V(g)[deg>0],netprod2,g,y)
    V(g)$deg2<- neighborhood.size(g, 2) - V(g)$deg - 1
    V(g)$tran<-transitivity(g, type="local",isolates="NaN")
#COMPUTING THE CENTRALITY VARIABLES
    gc<-get.giant.component(g)
    V(gc)$deg<-degree(gc)
    V(gc)$bet<-betweenness(gc)
    V(gc)$tr<-transitivity(gc, type="local",isolates="NaN")
    V(gc)$cl<-closeness(gc, normalized=TRUE)
    V(gc)$ev<-evcent(gc)$vector
   

    #d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran, V(g)$netprod,V(g)$netprod2)
    d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran)
    d2<-data.frame(V(gc)$auth,V(gc)$deg,V(gc)$bet,V(gc)$cl,V(gc)$ev, V(gc)$tr)

    write.csv(d,file=paste("network", endyear, "_", k, "y.csv", sep=""),na=".")
    write.csv(d2,file=paste("networkgc", endyear, "_", k, "y.csv", sep=""),na=".")
  }
}


#Restricted samples for the supplementary appendix


library(igraph)
source("getntwrks7auth.R")
#source("netprod_7authors.R")
#source("netprod2_7authors.R")
source("analyzenetw.R")

data<-read.csv("networkgenders70_7017.csv",header=TRUE)

# endyears and length to compute networks
ks <- 5
for (k in ks) {
 endyears <- (1970+k-1):2017

  for (endyear in endyears) {
    startyear <- endyear - k+1

    y <- subset(data,year>=startyear & year<=endyear)
    g <- getnetwork(startyear,endyear, data)
    y$auth7[is.na(y$auth7)]<--6 
    y$auth6[is.na(y$auth6)]<--5 
    y$auth5[is.na(y$auth5)]<--4 
    y$auth4[is.na(y$auth4)]<--3 
    y$auth3[is.na(y$auth3)]<--2 
    y$auth2[is.na(y$auth2)]<--1  

    V(g)$deg <- degree(g)
    #V(g)[deg>0]$netprod <- sapply(V(g)[deg>0],netprod,g,y)
    V(g)$auth<-V(g)
    #V(g)[deg>0]$netprod2<-sapply(V(g)[deg>0],netprod2,g,y)
    V(g)$deg2<- neighborhood.size(g, 2) - V(g)$deg - 1
    V(g)$tran<-transitivity(g, type="local",isolates="NaN")
#COMPUTING THE CENTRALITY VARIABLES
    gc<-get.giant.component(g)
    V(gc)$deg<-degree(gc)
    V(gc)$bet<-betweenness(gc)
    V(gc)$tr<-transitivity(gc, type="local",isolates="NaN")
    V(gc)$cl<-closeness(gc, normalized=TRUE)
    V(gc)$ev<-evcent(gc)$vector
   

    #d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran, V(g)$netprod,V(g)$netprod2)
    d<-data.frame(V(g)$auth,V(g)$deg,V(g)$deg2,V(g)$tran)
    d2<-data.frame(V(gc)$auth,V(gc)$deg,V(gc)$bet,V(gc)$cl,V(gc)$ev, V(gc)$tr)

    write.csv(d,file=paste("network", endyear, "_", k, "y.csv", sep=""),na=".")
    write.csv(d2,file=paste("networkgc", endyear, "_", k, "y.csv", sep=""),na=".")
  }
}

